package com.ruoyi.labsafety.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labsafety.domain.LabSafetyCheckRelIndexItem;
import com.ruoyi.labsafety.service.ILabSafetyCheckRelIndexItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安检检查指标项Controller
 * 
 * @author ruoyi
 * @date 2022-03-31
 */
@RestController
@RequestMapping("/labsafety/labSafetyCheckRefIndexItem")
public class LabSafetyCheckRelIndexItemController extends BaseController
{
    @Autowired
    private ILabSafetyCheckRelIndexItemService labSafetyCheckRelIndexItemService;

    /**
     * 查询安检检查指标项列表
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabSafetyCheckRelIndexItem labSafetyCheckRelIndexItem)
    {
        startPage();
        List<LabSafetyCheckRelIndexItem> list = labSafetyCheckRelIndexItemService.selectLabSafetyCheckRelIndexItemList(labSafetyCheckRelIndexItem);
        return getDataTable(list);
    }

    /**
     * 导出安检检查指标项列表
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:export')")
    @Log(title = "安检检查指标项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabSafetyCheckRelIndexItem labSafetyCheckRelIndexItem)
    {
        List<LabSafetyCheckRelIndexItem> list = labSafetyCheckRelIndexItemService.selectLabSafetyCheckRelIndexItemList(labSafetyCheckRelIndexItem);
        ExcelUtil<LabSafetyCheckRelIndexItem> util = new ExcelUtil<LabSafetyCheckRelIndexItem>(LabSafetyCheckRelIndexItem.class);
        return util.exportExcel(list, "item");
    }

    /**
     * 获取安检检查指标项详细信息
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(labSafetyCheckRelIndexItemService.selectLabSafetyCheckRelIndexItemById(id));
    }

    /**
     * 新增安检检查指标项
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:add')")
    @Log(title = "安检检查指标项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabSafetyCheckRelIndexItem labSafetyCheckRelIndexItem)
    {
        return toAjax(labSafetyCheckRelIndexItemService.insertLabSafetyCheckRelIndexItem(labSafetyCheckRelIndexItem));
    }

    /**
     * 修改安检检查指标项
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:edit')")
    @Log(title = "安检检查指标项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabSafetyCheckRelIndexItem labSafetyCheckRelIndexItem)
    {
        return toAjax(labSafetyCheckRelIndexItemService.updateLabSafetyCheckRelIndexItem(labSafetyCheckRelIndexItem));
    }

    /**
     * 删除安检检查指标项
     */
//    @PreAuthorize("@ss.hasPermi('labsafety:item:remove')")
    @Log(title = "安检检查指标项", businessType = BusinessType.DELETE)
	  @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(labSafetyCheckRelIndexItemService.deleteLabSafetyCheckRelIndexItemByIds(ids));
    }

    //    @PreAuthorize("@ss.hasPermi('labsafety:item:edit')")
    @Log(title = "安检检查指标项", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public AjaxResult updateStatus(@RequestBody LabSafetyCheckRelIndexItem labSafetyCheckRelIndexItem)
    {
        return toAjax(labSafetyCheckRelIndexItemService.updateLabSafetyCheckRelIndexItemStatus(labSafetyCheckRelIndexItem));
    }
}
